
function soapWrapFunc(bdStr){
    // 封装SOAP头尾
    var soapHead = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://Webservice.zjusc.edu.cn/"><env:Body>', soapTail = '</env:Body></env:Envelope>';
    return soapHead + bdStr + soapTail;
}
function loadConfig(){
	var dateReg = /\d{4}\-\d{2}\-\d{2}/;
	var str='<web:readConfig></web:readConfig>';
	$.ajax({
        type: "POST",
        contentType: "text/xml",
        url: '../../Service/ConfigService',
        data: soapWrapFunc(str),
        dataType: 'xml',
		success:function(xml){
			$.each($(xml).find("return"), function(i, n){

            	$('#txtYear').val($(this).find('year').text());
				$('#inStartTime').val(($(this).find("startTime").text()).match(dateReg));
				$('#inEndTime').val(($(this).find("endTime").text()).match(dateReg));
				$("input[name=sprOrAutu]").val([$(this).find("season").text()]);
				$("input[name=raApplyEnable]").val([$(this).find("register").text()]);
				$("input[name=raDownEnable]").val([$(this).find("load").text()]);
			});
			
		},
		beforeSend: function(xhr){
            xhr.setRequestHeader("SOAPAction", "\"\"");
        },
        error: function(x, e){
            alert('error:' + x.responseText);
        },
        complete: function(x){
        
        }
	});
}
$(function(){
	
	$('#saveButton').click(function(){
		//验证报文
	    var userinfo = '<uc><authCode>' + Tr0j4n.Cookie.Get('userCode') + '</authCode><userName>' + Tr0j4n.Cookie.Get('userName') + '</userName></uc>';
	    
		var year=$.trim($('#txtYear').val());
		var season=$.trim($('input[name=sprOrAutu]:checked').val());
		var startTime=$.trim($('#inStartTime').val());
		var endTime=$.trim($('#inEndTime').val());
		var register=$.trim($('input[name=raApplyEnable]:checked').val());
		var load=$.trim($('input[name=raDownEnable]:checked').val());
		
		var sendBody='<web:updateConfig>'+userinfo+'<cfg>'+
		'<year>'+year+'</year>'+
		'<season>'+season+'</season>'+
		'<startTime>'+startTime+'</startTime>'+
		'<endTime>'+endTime+'</endTime>'+
		'<register>'+register+'</register>'+
		'<load>'+load+'</load>'+
		'</cfg></web:updateConfig>';
		$.ajax({
            type: "POST",
            contentType: "text/xml",
            url: '../../Service/ConfigService',
            data: soapWrapFunc(sendBody),
            dataType: 'xml',
            success: function(xml){
                alert($(xml).find('return').text());
				 loadExamData();
            },
            beforeSend: function(xhr){
                xhr.setRequestHeader("SOAPAction", "\"\"");
            },
            error: function(x, e){
            	 var xmlObj = $(x.responseText);
                 if (xmlObj.find('faultstring').text() == 'oops') {
                     alert('您的权限认证失败，可能是密码已经泄露，请退出重新登录或联系管理员');
                     return;
                 }
                 else {
                     alert('error:' + x.responseText);
                 }
            },
            complete: function(x){
            
            }
        });
	});
});
/*
 *
 *
 */
$(window).load(function(){
	loadConfig();
    $('.sectionContent .timezone').datePicker({
        startDate: '2000-01-01',
        endDate: '2100-01-01',
        clickInput: true,
        verticalOffset: 35
    });
});
